package com.awcall.iot.service.impl;

import com.awcall.iot.common.ResponseResult;
import com.awcall.iot.mapper.SystemUserMapper;
import com.awcall.iot.model.Role;
import com.awcall.iot.model.SystemUser;
import com.awcall.iot.service.IOperateLogService;
import com.awcall.iot.service.IRoleService;
import com.awcall.iot.service.ISystemUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author wuhui
 * @since 2018-03-05
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements ISystemUserService {

    @Autowired
    private IRoleService roleService;

    @Autowired
    private IOperateLogService iOperateLogService;

    @Override
    public ResponseResult updateRole(SystemUser systemUser) {
        Role role1 = new Role();
        role1.setId(systemUser.getRoleId());
        Role role = roleService.selectById(role1);
        if (role == null) {
            return new ResponseResult(1, "角色为空");
        }
        updateById(systemUser);
        return new ResponseResult();
    }

    @Override
    public boolean isAdmin(Integer userId) {

        SystemUser systemUser = selectById(userId);

        if (null == systemUser) {
            return false;
        } else {

            if (null == systemUser.getRoleId() || 1 != systemUser.getRoleId()) {
                return false;
            }

        }

        return true;
    }

}
